package com.lanhao.aot.mail;

import java.util.ArrayList;

import org.springframework.ui.freemarker.FreeMarkerConfigurationFactory;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import com.beust.jcommander.internal.Maps;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.extra.mail.MailUtil;

public class TemplateMailUtil {
	public static void main(String[] args) {
		ArrayList<String> tos = CollUtil.newArrayList("kunzhou3@iflytek.com", "gwxu4@iflytek.com", "lanhaoooo@163.com");
		
		try {
			FreeMarkerConfigurationFactory factory = new FreeMarkerConfigurationFactory();
			factory.setTemplateLoaderPaths("classpath:tpl");
			factory.setDefaultEncoding("UTF-8");
			FreeMarkerConfigurer result = new FreeMarkerConfigurer();
			result.setConfiguration(factory.createConfiguration());
			String mailText = FreeMarkerTemplateUtil.getMailText(result, "email_template.ftl", Maps.newHashMap());
			System.out.println(mailText);
			MailUtil.send(tos, "销售出货单同步", mailText, true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
